package com.zp.qualitypractice.list.header;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.zp.qualitypractice.R;

/**
 * Created by izp on 2017/4/20.
 */

public class ListRefreshHeader extends BaseRefreshHeader {

    private int mContentHeight;

    public ListRefreshHeader(Context context) {
        super(context);
    }

    public ListRefreshHeader(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ListRefreshHeader(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public ListRefreshHeader(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

//    @Override
//    protected LinearLayout getHeaderContainerView(Context context) {
//        return (LinearLayout) LayoutInflater.from(context).inflate(R.layout.item_list_refresh_header,null,false);
//    }

    @Override
    public void initOther() {//base中也只是继承了LinearLayout,并没有向里面添加View,有一个已经inflate好的headerViewContent,但是没有添加到Group中
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
        addView(mHeaderViewContainer, lp);
        setGravity(Gravity.BOTTOM);
    }

    @Override
    public void updateCircle(float percent) {

    }

    /**
     * @param height
     * 到底哪个是用来动态修改高度的?
     */
    public void setShowHeight(int height) {
        if (height < 0) {//如果导读小于0,那么就设置高度为0
            height = 0;
        }

        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mHeaderViewContainer
                .getLayoutParams();
        lp.height = height;
        mHeaderViewContainer.setLayoutParams(lp);//重新设置layout的高度

        mHeaderCircle.update(Math.abs(height) * 1f/ mContentHeight);
    }

    public int getShowHeight() {
        return mHeaderViewContainer.getLayoutParams().height;
    }

    /**
     * @param height
     * 这个字面意思是设置内容高度
     */
    public void setContentHeight(int height) {
        this.mContentHeight = height;
    }
}
